package org.jivesoftware.smackx.search;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.ReportedData;
import org.jivesoftware.smackx.ReportedData.Column;
import org.jivesoftware.smackx.ReportedData.Field;
import org.jivesoftware.smackx.ReportedData.Row;
import org.xmlpull.v1.XmlPullParser;

class SimpleUserSearch extends IQ
{
  private ReportedData data;
  private Form form;

  private String getItemsToSearch()
  {
    String str3;
    StringBuilder localStringBuilder = new StringBuilder();
    if (this.form == null)
      this.form = Form.getFormFrom(this);
    if (this.form == null)
    {
      str3 = "";
      return str3;
    }
    Iterator localIterator = this.form.getFields();
    while (true)
    {
      String str1;
      String str2;
      do
      {
        while (!(localIterator.hasNext()))
          str3 = localStringBuilder.toString();
        FormField localFormField = (FormField)localIterator.next();
        str1 = localFormField.getVariable();
        str2 = getSingleValue(localFormField);
      }
      while (str2.trim().length() <= 0);
      localStringBuilder.append("<").append(str1).append(">").append(str2).append("</").append(str1).append(">");
    }
  }

  private static String getSingleValue(FormField paramFormField)
  {
    String str;
    Iterator localIterator = paramFormField.getValues();
    if (localIterator.hasNext())
      str = (String)localIterator.next();
    while (true)
    {
      return str;
      str = "";
    }
  }

  public String getChildElementXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<query xmlns=\"jabber:iq:search\">");
    localStringBuilder.append(getItemsToSearch());
    localStringBuilder.append("</query>");
    return localStringBuilder.toString();
  }

  public ReportedData getReportedData()
  {
    return this.data;
  }

  protected void parseItems(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    ReportedData localReportedData = new ReportedData();
    localReportedData.addColumn(new ReportedData.Column("JID", "jid", "text-single"));
    int i = 0;
    ArrayList localArrayList1 = new ArrayList();
    while (true)
    {
      int j;
      do
      {
        while (true)
        {
          while (true)
          {
            if (i != 0)
            {
              this.data = localReportedData;
              return;
            }
            if (paramXmlPullParser.getAttributeCount() > 0)
            {
              String str3 = paramXmlPullParser.getAttributeValue("", "jid");
              ArrayList localArrayList3 = new ArrayList();
              localArrayList3.add(str3);
              ReportedData.Field localField2 = new ReportedData.Field("jid", localArrayList3);
              localArrayList1.add(localField2);
            }
            j = paramXmlPullParser.next();
            if ((j != 2) || (!(paramXmlPullParser.getName().equals("item"))))
              break;
            localArrayList1 = new ArrayList();
          }
          if ((j != 3) || (!(paramXmlPullParser.getName().equals("item"))))
            break;
          localReportedData.addRow(new ReportedData.Row(localArrayList1));
        }
        if (j == 2)
        {
          String str1 = paramXmlPullParser.getName();
          String str2 = paramXmlPullParser.nextText();
          ArrayList localArrayList2 = new ArrayList();
          localArrayList2.add(str2);
          ReportedData.Field localField1 = new ReportedData.Field(str1, localArrayList2);
          localArrayList1.add(localField1);
          int k = 0;
          Iterator localIterator = localReportedData.getColumns();
          while (true)
          {
            label297: 
            do
              while (true)
              {
                do
                  if (localIterator.hasNext())
                    break label297;
                while (k != 0);
                ReportedData.Column localColumn = new ReportedData.Column(str1, str1, "text-single");
                localReportedData.addColumn(localColumn);
              }
            while (!(((ReportedData.Column)localIterator.next()).getVariable().equals(str1)));
            k = 1;
          }
        }
      }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("query"))));
      i = 1;
    }
  }

  public void setForm(Form paramForm)
  {
    this.form = paramForm;
  }
}